<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<head>
    <title>Hello Google Earth!</title>
    <!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
    <script src="http://www.google.com/jsapi?key=<%=(String) request.getSession().getAttribute("GoogleMapKey")%>"></script>
    <script>
        google.load("earth", "1");

        var ge = null;

        function init() {
            google.earth.createInstance("map3d", initCallback, failureCallback);
        }

        function initCallback(object) {
            ge = object;
            ge.getWindow().setVisibility(true);

//            var url = 'http://sketchup.google.com/' +
            //                      '3dwarehouse/download?mid=28b27372e2016cca82bddec656c63017&rtyp=k2';
        <%--var url = 'http://colab.ncsa.uiuc.edu:54321/ncsakml/kmlFileHandler.jsp?fileId=<%=(String) request.getSession().getAttribute("FileIdString")%>';--%>
            var url = 'http://localhost:8080/kml/<%=(String) request.getSession().getAttribute("FileIdString")%>';

            google.earth.fetchKml(ge, url, finished);

        }

        function finished(object) {
            if (!object) {
                alert('bad or NULL kml');
                return;
            }
            ge.getFeatures().appendChild(object);
            var la = ge.createLookAt('');
            la.set(37.77976, -122.418307, 25, ge.ALTITUDE_MODE_RELATIVE_TO_GROUND,
                    180, 60, 500);
            ge.getView().setAbstractView(la);
        }

        function failureCallback(object) {
        }

    </script>
</head>
<body onload='init()'>

<div>
    Hello, Earth!
</div>

<div id='map3d_container'
     style='border: 1px solid silver; height: 600px; width: 800px;'>
    <div id='map3d' style='height: 100%;'></div>
</div>
</body>
</html>